import websockets
import os
import asyncio

async def get_sesson(ws,path):
    if path == '/cbb':
        while 1:
            recv = await ws.recv()
            with open('./weipu.js', 'w', encoding='utf-8') as f:
                f.write(recv)
            # print(recv)
            os.system('node ./astWeiPu.js')
            with open('./weipu2.js', encoding='utf-8') as f:
                astText = f.read()
            print(astText)
            await ws.send(astText)
    ws.close()


if __name__ == '__main__':
    c_loop = asyncio.get_event_loop()
    asyncio.set_event_loop(c_loop)
    start_server = websockets.serve(get_sesson, '127.0.0.1', 5678)
    asyncio.get_event_loop().run_until_complete(start_server)
    asyncio.get_event_loop().run_forever()